<template>
	<el-container>
		<el-container>
			<el-header>
                <div class="left-panel">
					<!-- <el-button type="primary" @click="add" v-auth="'spare.add'">新增</el-button> -->
					<!-- <el-button type="primary" @click="batch_show" v-auth="'spare.add'" :disabled="selection.length !== 1">查看</el-button>
					<el-button type="primary" :disabled="selection.length !== 1" @click="batch_edit" v-auth="'spare.edit'">修改</el-button>
					<el-button type="danger" :disabled="selection.length == 0" @click="batch_del" v-auth="'spare.deleteAll'">删除</el-button>
					<el-button type="primary" @click="batch_show" v-auth="'spare.add'" :disabled="selection.length !== 1">启用</el-button>
					<el-button type="primary" @click="batch_show" v-auth="'spare.add'" :disabled="selection.length !== 1">禁用</el-button> -->
				</div>
				<div class="right-panel">
					<div class="right-panel-search">
						<el-input v-model="search.end_price" placeholder="检验项目编号/名称" clearable></el-input>
						<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
						<el-button type="info" @click="refresh">重置</el-button>
					</div>
				</div>
			</el-header>
			<el-main class="nopadding">
				<scTable @row-dblclick="dblclick" ref="table" :apiObj="apiObj" row-key="id"  @selection-change="selectionChange" stripe remoteSort remoteFilter border>
					<el-table-column type="selection" width="50" reserve-selection align="center"></el-table-column>
					<el-table-column label="单据编号" prop="check_code" width="120" align="center"></el-table-column>
					<el-table-column label="单据日期" prop="check_date" align="center" width="120"></el-table-column>
					<el-table-column label="物料编码" prop="goods_code" align="center" width="120"></el-table-column>
					<el-table-column label="物料名称" prop="goods_name" align="center" width="120"></el-table-column>
					<el-table-column label="物料规格" prop="goods_spec" align="center" width="120"></el-table-column>
					<el-table-column label="工序代码" prop="work_code" align="center" width="120"></el-table-column>
					<el-table-column label="工序名称" prop="work_name" align="center" width="120"></el-table-column>
					<el-table-column label="请检数量" prop="faskqty" align="center" width="120"></el-table-column>
					<el-table-column label="合格数量" prop="fcomqty" align="center" width="120"></el-table-column>
					<el-table-column label="不合格数量" prop="fnoqty" align="center" width="120"></el-table-column>
					<el-table-column label="请检人" prop="faskstuff_name" align="center" width="120"></el-table-column>
					<el-table-column label="检验员" prop="finspectorname" align="center" width="120"></el-table-column>
					<el-table-column label="业务状态" prop="status" align="center" width="120">
                        <template #default="scope">
							<el-tag :type="scope.row.status == 0 ? 'warning' : 'success' ">{{scope.row.status == 0 ? '报检' : '检验' }}</el-tag>
						</template>
                    </el-table-column>
					<el-table-column label="工序汇报单号" prop="foptbillno" align="center" width="120"></el-table-column>
					<el-table-column label="检验说明" prop="fdocument" align="center" width="120"></el-table-column>
					<el-table-column label="检验方案代码" prop="quality_code" align="center" width="120"></el-table-column>
					<el-table-column label="检验方案名称" prop="quality_name" align="center" width="120"></el-table-column>
                    <el-table-column label="操作" fixed="right" align="center" width="120">
                        <template #default="scope">
                            <el-button-group>
                                <el-button text type="primary" size="small" @click="table_add(scope.row)" v-if="scope.row.status == 0">检验</el-button>
                                <!-- <el-button text type="primary" size="small" @click="table_show(scope.row)" v-if="scope.row.status == 1">查看</el-button> -->
                            </el-button-group>
                        </template>
                    </el-table-column>
				</scTable>
			</el-main>
		</el-container>
	</el-container>
    <save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save = false"></save-dialog>
</template>

<script>
import saveDialog from './save.vue'
export default {
	name: 'user',
	components: {saveDialog},
	data() {
		return {
			dialog: {
				save: false,
			},
			group: [],
			apiObj: this.$API.production.checkorder.list,
			selection: [],
			search: {
				title: null,
				cid: null,
			},
        }
	},
	methods: {
        table_add(row){
            this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('add').setData(row)
			})
        },
		/**查看点击*/
		batch_show() {
			this.dialog.details = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open('add')
			})
		},
		//查看
		table_show(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('show').setData(row)
			})
		},
		//表格内开关
		async changeSwitch(val, row) {
			row.$switch_status = true;
			var res = await this.$API.basicdata.applyList.update_status.post({
				id: row.id,
				system_disable: row.system_disable,
			});
			if (res.code == 1) {
				row.$switch_status = false;
				this.$refs.table.refresh();
				this.$message.success("操作成功");
			} else {
				this.$alert(res.message, "提示", {type: "error"});
			}
		},
		//删除
		async table_del(row, index) {
			var reqData = {id: row.id}
			var res = await this.$API.production.checkorder.delete.post(reqData);
			if (res.code == 1) {
				//这里选择刷新整个表格 OR 插入/编辑现有表格数据
				this.$refs.table.tableData.splice(index, 1);
				this.$refs.table.refresh();
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//搜索
		upsearch() {
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSuccess(data, mode) {
			if (mode == 'add') {
				this.$refs.table.refresh()
			} else if (mode == 'edit') {
				this.$refs.table.refresh()
			}
		},
		selectionChange(selection) {
			this.selection = selection;
		},
	}
}
</script>

<style>
.search-input {
	width: auto;
	font-size: 14px;
}

.shopInfo {
	display: flex;
	align-items: center;
}

.img {
	width: 100px;
	height: 100px;
	margin-right: 5px;
}
</style>
